package com.lsh.oms.provider.service.shipping;

import com.alibaba.dubbo.config.annotation.Service;
import com.google.common.collect.Lists;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.service.shipping.IShippingOrderRestService;
import com.lsh.oms.core.constant.ReturnCode;
import com.lsh.oms.core.service.shipping.core.ShippingService;
import com.lsh.oms.provider.service.BaseService;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@Path("shipping-orders")
@Service(protocol = "rest", timeout = 30000)
public class ShippingOrderRestServiceImpl extends BaseService implements IShippingOrderRestService {

    @Resource
    private ShippingService shippingService;

    @GET
    @Produces({MediaType.APPLICATION_JSON})
    @Override
    public CommonResult<Map<String, Object>> findShippingByOrderId(@QueryParam("order-id") Long orderId) {
        Map<String, Object> shipping = shippingService.findShippingDetailsByOrderId(orderId);
        CommonResult<Map<String, Object>> responseBody = new CommonResult<>();
        responseBody.setCode(ReturnCode.REQUEST_SUCCESS);
        responseBody.setData(buildPage(shipping));
        return responseBody;
    }

    private Map<String, Object> buildPage(Map<String, Object> item) {
        Map<String, Object> page = new HashMap<>();
        page.put("total_count", 1L);
        page.put("total_page", 1L);
        page.put("page", 1L);
        page.put("entries", Lists.newArrayList(item));
        return page;
    }
}
